package com.hyw.cm.server;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import org.springframework.lang.Nullable;

import io.netty.channel.Channel;

/**
 * 于进程内，维护设备ID与具体连接通道的上下文
 * 
 * @author Hongyu
 */
public final class ConnectionContext {
  private static final Map<String, Channel> holder = new ConcurrentHashMap<>(1024);

  public static boolean exists(String id) {
    return holder.containsKey(id);
  }

  public static void put(String id, Channel channel) {
    holder.put(id, channel);
  }

  public static @Nullable Channel get(String id) {
    return holder.get(id);
  }

  public static @Nullable Channel remove(String id) {
    return holder.remove(id);
  }
}
